package com.sphd.Restaurant.base;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sphd.Restaurant.R;


import java.math.BigDecimal;

/**
 * Created by Hu on 2016/9/25.
 */

public abstract class BaseFragment extends Fragment {
    public Context context;
    public SharedPreferences remember;
    public ProgressDialog mDialog;
    boolean isViewCreated;
    public BaseActivity activity;
    private View footView;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        activity= (BaseActivity) getActivity();
        Log.e("BaseFragment", "onCreateView");
        remember = MyApplication.getRemember();
        Log.e("reme", "reme");
        context = getContext();
        footView=View.inflate(context,R.layout.foot_view, null);
        View rootView = inflater.inflate(getLayout(), container, false);
        initViews(rootView);
        isViewCreated = true;
        return rootView;
    }

    public void setRefresh(SwipeRefreshLayout myRefreshLayout) {
        activity.setRefresh(myRefreshLayout);
//        myRefreshLayout.setColorSchemeResources(
//                android.R.color.holo_blue_light, android.R.color.holo_red_light,
//                android.R.color.holo_orange_light, android.R.color.holo_green_light);
    }

    public void setRecycle(RecyclerView mRecy) {
        activity.setRecycle(mRecy);
//        mRecy.setLayoutManager(new LinearLayoutManager(context));
//        mRecy.addItemDecoration(new DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL_LIST));
    }

    public void setRecy(RecyclerView mRecy) {
        activity.setRecy(mRecy);
//        recy.setHasFixedSize(true);
//        recy.setLayoutManager(new LinearLayoutManager(context));
//        recy.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST));
    }

    public void setGridRecy(RecyclerView recy) {
        activity.setGridRecy(recy);
//        recy.setHasFixedSize(true);
//        recy.setLayoutManager(new GridLayoutManager(context, 2));
    }

    public void toast(String s) {
        activity.toast(s);
//        Toast.makeText(context, s, Toast.LENGTH_SHORT).show();
    }
    public  boolean contains(String key){
        return activity.contains(key);
    }
    public void showDialog() {
       activity.showDialog();
    }

    public void dissMissDialog() {
        activity.dissMissDialog();
    }

    public boolean isMNC() {
        return activity.isMNC();
    }

    public abstract int getLayout();

    public abstract void initViews(View rootView);

    public void startActivity(Class<?> cls) {
       activity.startActivity(cls);
    }


    public void putString(String key, String val) {
//        remember.edit().putString(jiami(key), jiami(val)).commit();
//        remember.edit().putString(key, val).commit();
        activity.putString(key, val);
    }

    public void removeKey(String key) {
//        remember.edit().remove(key).commit();
        activity.removeKey(key);
    }

    public void putBoolean(String key, boolean val) {
//        remember.edit().putBoolean(jiami(key), val).commit();
//        remember.edit().putBoolean(key, val).commit();
        activity.putBoolean(key, val);
    }

    public void putInt(String key, int val) {
//        remember.edit().putInt(jiami(key), val).commit();
//        remember.edit().putInt(key, val).commit();
        activity.putInt(key, val);
    }

    public void putLong(String key, long val) {
//        remember.edit().putLong(jiami(key), val).commit();
        remember.edit().putLong(key, val).commit();
        activity.putLong(key, val);
    }

    public String getString(String key) {
        return activity.getString(key);
    }

    public int getInt(String key) {

        return activity.getInt(key);
    }

    public long getLong(String key) {
        return activity.getLong(key);
    }

    public boolean getBoolean(String key) {
return activity.getBoolean(key);
    }

    /**
     * @param val
     * @return 加密
     */
    public String jiami(String val) {

        return activity.jiami(val);
    }

    /**
     * @param val
     * @return 解密
     */
    public String jiemi(String val) {
        return activity.jiemi(val);
    }


    public void startActivity(Class<?> cls, Bundle bundle) {
      activity.startActivity(cls,bundle);
    }

    public Bundle crratBundle() {
        return activity.crratBundle();
    }

    public BigDecimal turn(String val, int i) {
        return activity.turn(val, i);
    }

    public BigDecimal turn(double val, int i) {
        return activity.turn(val, i);
    }

    public BigDecimal turn(float val, int i) {
        return activity.turn(val, i);
    }

    public void setImage(ImageView image, String url) {
       activity.setImage(image,url);
    }


    public void addFootView(BaseQuickAdapter baseQuickAdapter) {
        baseQuickAdapter.removeAllFooterView();
        baseQuickAdapter.addFooterView(footView);
    }
}
